#ifndef HIBERNATE_H
#define HIBERNATE_H

#include <avr/sleep.h>

// {{{ wakeUp(): wake up from hibernation
/// This is the callback function for waking up the Arduino
void wakeUp()
{
	// Nothing to be done
}

// }}}

// {{{ goToSleep(): hibernate
/// This function will put the Arduino to sleep
void goToSleep()
{
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
	sleep_enable();

	if (ISINPUT(2))
		attachInterrupt(0, wakeUp, LOW);	// Pin 2
	if (ISINPUT(3))
		attachInterrupt(1, wakeUp, LOW);	// and 3 will wake up the system

	sleep_mode();
	sleep_disable();

	if (ISINPUT(2))
		detachInterrupt(0);
	if (ISINPUT(3))
		detachInterrupt(1);
}

// }}}


#endif
